Page({
  data: {
    dialogVisible: false,
    // 房屋列表
    houseList: [],
  },
  onShow() {
      this.initData()
    
  },
  // 获取列表
  async initData() {
    const houseList = await wx.http.get('/room')
    // console.log(res);
    this.setData({ houseList })
  },
  swipeClose(ev) {
    const { position, instance } = ev.detail
    this.id = ev.mark.id
    this.index = ev.mark.index
    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })

      // swiper-cell 滑块关闭
      instance.close()
    }
  },
  // 删除
  async dialogClose(ev) {
    // console.log(ev.detail);
    // 判断是否点击的是确定按钮
    if (ev.detail === 'confirm') {
      // 删除请求
      await wx.http.delete('/room/' + this.id)
      // 手动更新数据
      this.data.houseList.splice(this.index, 1)
      this.setData({ houseList: this.data.houseList })
    }
  },
  goDetail(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + ev.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
